package com.zcyh.exam.controller.student;


import com.zcyh.exam.controller.BaseController;
import com.zcyh.exam.model.common.Result;
import com.zcyh.exam.model.common.ResultCode;
import com.zcyh.exam.model.request.PageParam;
import com.zcyh.exam.service.education.ExamInfoService;
import com.zcyh.exam.service.education.TestPaperInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 学生端试卷管理
 * @author zengjintao
 * @version 1.0
 * @create_at 2020/11/22 10:26
 */
@RestController("student-testPaperInfo")
@RequestMapping("/student/testPaperInfo")
public class TestPaperInfoController extends BaseController {

    @Autowired
    private TestPaperInfoService testPaperInfoService;
    @Autowired
    private ExamInfoService examInfoService;

    /**
     * 试卷列表
     * @param pageParam
     * @return
     */
    @GetMapping("list")
    public Result list(PageParam pageParam) {
        return Result.success(testPaperInfoService.selectStudentPageList(pageParam));
    }
    /**
     * 获取试卷试题
     * 不能使用缓存
     * @param id 试卷id
     * @return
     */
    @GetMapping("selectPaperQuestionById")
//    @Cacheable(cacheNames = CacheKey.TEST_PAPER_INFO_CACHE, key = "#id")
    public Result selectPaperQuestionById(String id) {
        PageParam pageParam = new PageParam(); // 设置不分页
        return Result.success(testPaperInfoService.selectStudentPaperQuestionList(pageParam, id)) ;
    }

    /**
     * 提交题目答案
     * @param testPaperInfoId
     * @param questionInfoId
     * @param studentAnswer
     * @return
     */
    @PostMapping("commitQuestion")
    public Result commitQuestion(@RequestParam String testPaperInfoId,
                                 @RequestParam String questionInfoId,
                                 @RequestParam String studentAnswer){
        examInfoService.commitQuestion(testPaperInfoId,questionInfoId,studentAnswer);
        return Result.success(ResultCode.SUCCESS, "提交成功");
    }

    /**
     * 提交试卷试题
     * @return
     */
    @PostMapping("commitPaper")
    public Result commitPaper(@RequestParam String testPaperInfoId) {
        examInfoService.commitTestPaperInfo(testPaperInfoId);
        return Result.success(ResultCode.SUCCESS, "提交成功");
    }

    /**
     * 提交试卷试题 --- old
     * @param studentQuestionRequest
     * @return
     */
//    @PostMapping("commitPaper")
//    public Result commitPaper(@RequestBody StudentQuestionRequest studentQuestionRequest) {
//        String examInfoId = examInfoService.commitTestPaperInfoQuestion(studentQuestionRequest);
//        return Result.success(ResultCode.SUCCESS, "提交成功", examInfoId);
//    }

}
